<?php
/**
 * Created by PhpStorm.
 * User: yangjiaming
 * Date: 2018/2/5
 * Time: 15:19
 */

namespace Halo\Data;


class Remote
{
    private static $connections = [
        'db' => array(),
        'redis' => array()
    ];
    public static function getDb($conf)
    {
        $config = is_array($conf)?$conf:$config = [
            'host' => DB_HOST,
            'port' => DB_PORT,
            'user' => DB_USER,
            'pass' => DB_PASS,
            'dbname' => $conf
        ];
        return new Mysql($config);
    }

    public static function close($type, $name = '')
    {
        if (isset(static::$connections[$type])) {
            //unset(static::$connections[$type][$name]);
            if(php_sapi_name() == 'cli' || empty($name)) {
                unset(static::$connections[$type]);
            }else {
                unset(static::$connections[$type][$name]);
            }
        }
    }
}